package com.lagou.client;

import com.lagou.service.UserService;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

public class ClientBootStrap {

    public static CuratorFramework startZkClient(){
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3);
        CuratorFramework client = CuratorFrameworkFactory.builder() .connectString("127.0.0.1:2181") //server地址
                .sessionTimeoutMs(5000) .connectionTimeoutMs(3000) .retryPolicy(retryPolicy) .namespace("netty-server") .build(); //
        client.start();
        return client;
    }

    public static void main(String[] args) throws Exception {

        CuratorFramework client = startZkClient();
        RpcConsumer rpcConsumer = new RpcConsumer(client);
        UserService proxy = (UserService) rpcConsumer.createProxy(UserService.class);
        while (true){
            Thread.sleep(2000);
            String s = proxy.sayHello("are you ok?");
            System.out.println(s);
            System.out.println("==================");
        }
    }
}
